package org.jfonia.connect5.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.jfonia.connect5.basics.BasicValueNode;
import org.jfonia.connect5.basics.MutableValueNodeDecorator;
import org.jfonia.connect5.relations.Equal;

/**
 * @author wijnand.schepens@hogent.be
 */
public class MyTextFieldDemo
{

	public static void main(String[] args)
	{
		SwingUtilities.invokeLater(new Runnable()
		{

			public void run()
			{
				JFrame frame = new JFrame("test");

				JPanel contentPanel = new JPanel();
				frame.setContentPane(contentPanel);
				contentPanel.setLayout(new BorderLayout());

				//JPanel buttonPanel = new JPanel();
				//contentPanel.add(buttonPanel, BorderLayout.NORTH);

				JPanel centerPanel = new DemoPanel();
				contentPanel.add(centerPanel, BorderLayout.CENTER);

				frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				frame.pack();
				frame.setLocationRelativeTo(null);
				frame.setVisible(true);
			}
		});
	}
}


class DemoPanel extends ComponentPanel
{

	DemoPanel()
	{
		this.setLayout(null);
		this.setPreferredSize(new Dimension(400, 400));

		MyTextField chord1 = new MyTextField("Am");
		this.add(chord1);

		MyTextField chord2 = new MyTextField("G");
		this.add(chord2);

		MyTextField lyric1 = new MyTextField("Hello");
		this.add(lyric1);

		MyTextField lyric2 = new MyTextField("is it me");
		this.add(lyric2);


		BasicValueNode<Integer> frame1x = new BasicValueNode<Integer>(0);
		BasicValueNode<Integer> frame2x = new BasicValueNode<Integer>(0);
		BasicValueNode<Integer> staff1y = new BasicValueNode<Integer>(0);
		BasicValueNode<Integer> staff2y = new BasicValueNode<Integer>(0);

		BasicValueNode<Integer> left = new BasicValueNode(10);
		BasicValueNode<Integer> right = new BasicValueNode(400);
		BasicValueNode<Integer> top = new BasicValueNode(10);
		BasicValueNode<Integer> bottom = new BasicValueNode(100);


		new Equal(frame1x, chord1.getXNode());
		new Equal(frame1x, lyric1.getXNode());
		new Equal(frame2x, chord2.getXNode());
		new Equal(frame2x, lyric2.getXNode());

		new Equal(staff1y, chord1.getYNode());
		new Equal(staff1y, chord2.getYNode());
		new Equal(staff2y, lyric1.getYNode());
		new Equal(staff2y, lyric2.getYNode());

		this.add(new Line(left, staff1y, right, staff1y));
		this.add(new Line(left, staff2y, right, staff2y));
		this.add(new Line(frame1x, top, frame1x, bottom));
		this.add(new Line(frame2x, top, frame2x, bottom));

		//this.addComponent(new DragHandle(frame1x, new MutableNodeDecorator(top)));
		this.add(new DragHandle(frame1x, new MutableValueNodeDecorator(top)));
		this.add(new DragHandle(frame2x, new MutableValueNodeDecorator(top)));
		this.add(new DragHandle(new MutableValueNodeDecorator(top), staff1y));
		this.add(new DragHandle(new MutableValueNodeDecorator(top), staff2y));

		//this.add(new DragHandle(new BasicNode<Integer>(50),new BasicNode<Integer>(80)));

		frame1x.setValue(30);
		frame2x.setValue(130);
		staff1y.setValue(20);
		staff2y.setValue(80);
		//tf1.setLocation(40,10);

	}


}
